 <template>
  <div class="wrap">
    <div class="sel">
      <div class="txt">关键词</div>
      <input v-model="form.keyWord"
        type="text"
        placeholder="用户名/手机号">
      <div class="btn"
        @click="querys()" style="cursor: pointer;">搜索</div>
    </div>
    <div class="clear"></div>
    <div class="titles">
      用户列表
    </div>
        <el-table :data="userList" stripe style="width: 100%">
      
        <el-table-column align="center"  label="头像">
          <template slot-scope="scope">
            <img :src="scope.row.userImg"
            style="height:100px;width:100px;"
              alt>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="nickName" label="用户名称"></el-table-column>
        <el-table-column align="center" prop="userPhone" label="手机号"></el-table-column>
        <el-table-column align="center" prop="registerTime" label="注册时间">
          <template slot-scope="scope">
            <div>
              <p>{{setDate(scope.row.registerTime)}}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center"  label="操作">
          <template slot-scope="scope">
            <el-button 
              type="primary" size="mini" round
              @click="setUser(scope.row.states,scope.row.id)"
            > {{scope.row.states == 1 ? '解除禁止' : '禁止'}}</el-button>
          </template>
        </el-table-column>
    </el-table>
    <div style="text-align: center;padding: 50px 0;">
      <el-pagination background
        layout="prev, pager, next"
        @current-change="changePage"
        :page-count="pageTotal">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import axios from "axios";
import qs from "qs";
export default {
  data() {
    return {
      loading: false,
      userList: [],
      pageTotal: 1,
      // 页面初始化
      form: {
        keyWord: "",
        page: "1",
        limit: ""
      }
    };
  },
  mounted: function() {
    this.getUserList();
  },
  methods: {
    // 分页
    changePage(argv) {
      this.form.page = argv;
      this.getUserList();
    },
    /**
     * 冻结
     */
     setUser: function (state,id) {
       let that = this;
      that.$confirm(state==0 ?'是否禁止该用户？' : '是否解除禁止该用户？').then( ()=>{
        if(state == 0) {
          state = 1
        } else {
          state = 0
        }
        axios({
        method: "post",
        url: `${that.$store.state.url}/tUser/updateStates`,
        data: qs.stringify({
          id:id,
          states:state
        })
      }).then(res => {
        that.userList = res.data.data;
        if (res.data.code == 0) {
          that.getUserList();
          let logData = {
                loginTime:this.$cookie.get("loginTime"),
                account:this.$cookie.get("userAccount"),
                content:state == 0 ? '禁止用户' : '解除禁止用户',
              operationTime:this.setDate(new Date()) + ' ' +this.setTime(new Date())
              }
              axios({
          method: "post",
          url: `${that.$store.state.url}/log/addLog`,
          data: qs.stringify(logData)
        }).then( (res) => {
          console.log(res,'222')
        })
        } else {
          that.$alert(res.data.msg)
        }
      }).catch(err => {
        
      });
      })
     },
    // 点击搜索
    querys: function() {
      this.getUserList();
    },
     /**
     * 根据时间毫秒数 返回年月日
     */
    setDate: function(str) {
      let times = new Date(str);
      return `${times.getFullYear()}-${
        times.getMonth() + 1 < 10
          ? "0" + (times.getMonth() + 1)
          : times.getMonth() + 1
      }-${times.getDate() < 10 ? "0" + times.getDate() : times.getDate()}`;
    },
    /**
     * 根据时间毫秒数 返回时分秒
     */
    setTime: function(str) {
      let times = new Date(str);
      return `${
        times.getHours() < 10 ? "0" + times.getHours() : times.getHours()
      }:${
        times.getMinutes() < 10 ? "0" + times.getMinutes() : times.getMinutes()
      }:${
        times.getSeconds() < 10 ? "0" + times.getSeconds() : times.getSeconds()
      }`;
    },
    // 查询用户
    getUserList: function() {
      this.loading = true;
      let that = this;
      axios({
        method: "post",
        url: `${that.$store.state.url}/tUser/selectByKyWord`,
        data: qs.stringify(that.form)
      }).then(res => {
        this.userList = res.data.data;
        if (res.data.code == 0) {
          this.pageTotal = Math.ceil(res.data.count / 10);
        }
        this.loading = false;
      }).catch(err => {
        this.loading = false;
      });
    },
    editParMan: function() {
      this.$router.push({
        path: "main/editParMan"
      });
    },
    accParMan: function() {
      this.$router.push({
        path: "main/accParMan"
      });
    }
  }
};
</script>
<style scoped>
.wrap {
  width: 90%;
  margin: 40px auto;
}
.titles {
  height: 62px;
  line-height: 62px;
  color: #778ca2ff;
  font-size: 14px;
  width: 100%;
  display: inline-block;
}
.sel {
  height: 32px;
  line-height: 32px;
  padding: 23px 20px;
  background: #fff;
}
.sel .txt {
  float: left;
  font-family: PingFangSC-Medium;
  font-size: 14px;
  color: rgba(37, 38, 49, 1);
  font-weight: bold;
  width: 42px;
}
.sel input {
  float: left;
  width: 232px;
  height: 32px;
  background: rgba(255, 255, 255, 1);
  border-radius: 16px;
  border: 1px solid rgba(232, 236, 239, 1);
  color: #888888;
  margin-left: 17px;
  text-align: center;
  box-sizing: border-box;
  outline: none;
}
.btn {
  float: left;
  color: #fff;
  width: 80px;
  height: 32px;
  background: rgba(75, 116, 255, 1);
  border-radius: 24px;
  border: 1px solid rgba(75, 116, 255, 1);
  text-align: center;
  margin-left: 37px;
}

.addpar {
  float: right;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
  width: 114px;
  height: 32px;
  background: rgba(75, 116, 255, 1);
  border-radius: 24px;
  border: 1px solid rgba(75, 116, 255, 1);
  text-align: center;
  line-height: 32px;
}
</style>
